package com.yihukurama.base.framework.domain.tkmapper.entity;


import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihukurama.base.app.annotation.SqlWhere;
import com.yihukurama.base.app.constant.MagicCode;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * 说明： 数据实体基类
 * @Author yihukurma
 * @date Created in 下午 3:15 2023/6/16 0016
 *  modified by autor in 下午 3:15 2023/6/16 0016
 */
@Data
public class BaseEntity implements Cloneable, Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * 主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    protected String id;

    /**
     * 批量id处理字段
     */
    private List<String> ids;
    /**
     * 拼在单表查询后的sql
     * order by (xxx,xxx desc/asc)括号部分
     */
    @Transient
    protected String sortSql;

    /**
     * 拼在单表查询后的sql
     * where (xx=xx)括号部分
     */
    @Transient
    protected String whereSql;

    /**
     *创建时间
     **/
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @JSONField(format="yyyy-MM-dd HH:mm:ss")@Column(name="create_time")
    protected Date createTime;
    /**
     *  创建人
     */
    @Column(name="create_by")
    protected String createBy;

    /**
     *创建时间
     **/
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @JSONField(format="yyyy-MM-dd HH:mm:ss")@Column(name="update_time")
    protected Date updateTime;

    /**
     *  更新人
     */
    @Column(name="update_by")
    private String updateBy;


    @SqlWhere(value = SqlWhere.SqlWhereValue.IN,proprtityName = MagicCode.ID)
    public List<String> getIds() {
        return ids;
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        BaseEntity that = (BaseEntity) o;
        return Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
